<template>
  <div class="account-info-page">
    <my-card title="账号信息">
      <template slot>
        <div class="account-info-box">
          <el-form ref="form" :model="formData" label-width="120px">
            <el-form-item>
              <div class="item-title-box">基本信息</div>
            </el-form-item>
            <el-form-item label="用户名：">
              <el-input v-model="userInfo.account" disabled></el-input>
            </el-form-item>

            <el-form-item label="公司名称：">
              <el-input v-model="userInfo.companyName" disabled></el-input>
            </el-form-item>
            <el-form-item label="官网名称：">
              <el-input v-model="userInfo.officialNetName" disabled></el-input>
            </el-form-item>
            <el-form-item label="企业官网地址：">
              <el-input v-model="userInfo.mainSite" disabled></el-input>
            </el-form-item>
            <el-form-item>
              <div class="item-title-box">详细信息</div>
            </el-form-item>
            <el-form-item label="所在省市：">
              <el-input v-model="formData.location"></el-input>
            </el-form-item>
            <el-form-item label="联系人：">
              <el-input v-model="formData.name"></el-input>
            </el-form-item>
            <el-form-item label="联系地址：">
              <el-input v-model="formData.address"></el-input>
            </el-form-item>
            <el-form-item label="手机号码：">
              <el-input v-model="formData.phone"></el-input>
            </el-form-item>
            <el-form-item label="邮箱地址：">
              <el-input v-model="formData.email"></el-input>
            </el-form-item>
            <el-form-item>
              <div class="item-title-box">发票地址</div>
            </el-form-item>
            <el-form-item label="收件人：">
              <el-input v-model="formData.iReceiver"></el-input>
            </el-form-item>
            <el-form-item label="邮寄地址：">
              <el-input v-model="formData.iAddress"></el-input>
            </el-form-item>
            <el-form-item label="手机号码：">
              <el-input v-model="formData.iPhone"></el-input>
            </el-form-item>
            <el-form-item label="邮政编码：">
              <el-input v-model="formData.iPostCode"></el-input>
            </el-form-item>
            <el-form-item>
              <div class="bottom-btn-box">
                <el-button type="primary" @click="hkSubmit">保存</el-button>
                 <el-button type="primary" @click="cancellation">账户注销</el-button>
<!--                 <el-button @click="hkClickBack">返回</el-button>-->
              </div>
            </el-form-item>
          </el-form>
        </div>
      </template>
    </my-card>
  </div>
</template>

<script>
import MyCard from "@/components/my-card/index";
import {
  hkHidLoading,
  hkShowErrorText,
  hkShowLoading,
  hkShowSuccessText,
  isNull
} from "@/utils/tools";
import { hkPut } from "@/api/http";
import { httpApi } from "@/api/api";
export default {
  components: { MyCard },
  props: {},
  data() {
    return {
      userInfo: {
        account: "",
        companyName: "", //公司名称
        officialNetName: "", // 企业认证后的官方网站的名字
        officialNet: "" // 企业认证后的官方网站
      },
      formData: {
        location: "",
        name: "", // 用户姓名
        address: "", // 用户联系地址
        phone: "", // 电话号码,需唯一
        email: "", // 用户的邮箱
        iReceiver: "", // 企业用户邮件接收人
        iAddress: "", // 企业用户邮件接收地址
        iPhone: "", // 企业用户邮件接收联系方式
        iPostCode: "" // 企业用户邮件接收邮政编码
      }
    };
  },
  watch: {},
  computed: {},
  methods: {
    cancellation(){
      this.$router.push({path:"/account/user/cancel"})
      // this.$router.push({name:"account-info-66"})

    },
    hkClickBack() {
      this.$router.back();
    },
    hkSubmit() {
      let params = {};
      for (let key in this.formData) {
        if (this.formData[key] != this.userInfo[key]) {
          params[key] = this.formData[key];
        }
      }
      if (isNull(params)) {
        return;
      }
      hkShowLoading("修改中....");

      hkPut(httpApi.userEdit, params, false)
        .then(res => {
          hkHidLoading();
          hkShowSuccessText("修改成功!");
        })
        .catch(err => {
          hkHidLoading();
          hkShowErrorText(err.message);
        });
    }
  },
  created() {},
  mounted() {
    this.userInfo = this.$store.state.user.userInfo;
    for (let key in this.formData) {
      this.formData[key] = this.userInfo[key];
    }
    if (this.userInfo.officialNetName=="null"){
      this.userInfo.officialNetName="--"

    }
  }
};
</script>
<style lang="scss" scoped>
.is-disabled {
  ::v-deep .el-input__inner {
    color: #606266 !important;
  }
}
.account-info-box {
  width: 700px;
  margin: 0 auto;
  .item-title-box {
    text-align: center;
  }
  .bottom-btn-box {
    text-align: center;
  }
  .bottom-btn-box-a{
    color:#AFAFAF;
    margin-left: 50px;
  }
}
</style>
